import 'package:flutter/material.dart';
import 'package:flutter/services.dart';

class HomeList extends StatelessWidget {
  HomeList({super.key, required this.listData});
//卡片内容定义
  List listData = [
    {
      'title': '中秋、国庆温馨提示中秋、国庆温馨提示',
      'content': '中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示',
      'createdAt': '2024-09-22 15:00:00',
    },
    {
      'title': '中秋、国庆温馨提示中秋、国庆温馨提示',
      'content': '中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示',
      'createdAt': '2024-09-22 15:00:00',
    },
    {
      'title': '中秋、国庆温馨提示中秋、国庆温馨提示',
      'content': '中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示中秋、国庆温馨提示',
      'createdAt': '2024-09-22 15:00:00',
    },
  ];
  @override
  Widget build(BuildContext context) {
    return SizedBox(
        width: MediaQuery.of(context).size.width,
        child: Column(
          children: [
            //图片
            Container(
              margin: const EdgeInsets.only(top: 10),
              // padding: const EdgeInsets.all(10),
              // color: Colors.orange,
              child: //图片
                  Image.asset('assets/images/banner@2x.jpg', height: 120),
            ),
            //社区公告
            Row(
              children: [
                Container(
                  margin: const EdgeInsets.all(10),
                  child: Image.asset(
                    'assets/images/notice@2x.png',
                    width: 25,
                  ),
                ),
                const Text(
                  '社区',
                  style: TextStyle(fontWeight: FontWeight.bold),
                ),
                const Text(
                  '公告',
                  style: TextStyle(
                      color: Color.fromRGBO(231, 182, 97, 1),
                      fontWeight: FontWeight.bold),
                )
              ],
            ),

            //底部卡片区域
            Container(
                margin: const EdgeInsets.only(bottom: 10),
                // color: Colors.amber,
                child: ListView.builder(
                    //控制滚动组件大小以适配内容。
                    shrinkWrap: true,
                    // physics: const NeverScrollableScrollPhysics(),
                    itemCount: listData.length,
                    itemBuilder: (BuildContext context, int index) {
                      return GestureDetector(
                        //点击跳转至详情页面->传递id
                        onTap: () {
                          Navigator.pushNamed(context, '/detail',
                              arguments: {'id': listData[index]['id']});
                        },
                        child: Container(
                          padding: const EdgeInsets.all(10),
                          margin: const EdgeInsets.only(
                              left: 10, right: 10, bottom: 10),
                          decoration: BoxDecoration(
                            color: Colors.white,
                            borderRadius: BorderRadius.circular(10),
                          ),
                          child: Column(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.start,
                            children: [
                              Text(
                                listData[index]['title'],
                                style: const TextStyle(
                                    fontWeight: FontWeight.bold),
                              ),
                              const SizedBox(height: 5),
                              Text(
                                listData[index]['content'],
                                maxLines: 2,
                                style: const TextStyle(
                                  overflow: TextOverflow.ellipsis,
                                ),
                              ),
                              const SizedBox(height: 10),
                              Text(listData[index]['createdAt']),
                            ],
                          ),
                        ),
                      );
                    })),
          ],
        ));
  }
}
